
import time
from log.log import test_log
from common.mysql import mysql

def pytest_terminal_summary(terminalreporter):



    #统计总数量
    _TOTAL=terminalreporter._numcollected
    _PASSED= len(terminalreporter.stats.get('passed',[]))
    _FALLED = len(terminalreporter.stats.get('failed', []))
    _ERROR= len(terminalreporter.stats.get('error', []))
    _SKIP = len(terminalreporter.stats.get('skipped', []))
    _RERUN= len(terminalreporter.stats.get('rerun', []))
    _TIMES= round(time.time()-terminalreporter._sessionstarttime,2)   #测试用时，保留2位


    # 配置文件地址
    config_path = "config\YingXiao.ini"
     # 读取sql配置文件并连接数据库
    testcase='testcase'
    db_summary = mysql(config_path,testcase)
    text='UPDATE t_testcase_summary SET TOTAL = {}, PASSED = {}, FALLED = {}, ERROR = {}, SKIP = {}, RERUN = {}, TIMES = {} where id=1'.format(_TOTAL,_PASSED,_FALLED,_ERROR,_SKIP,_RERUN,_TIMES)
    db_summary.upadate(text)

    test_log.info("用例总数:{}，成功个数:{}，失败个数:{}，错误个数:{}，失败用例重跑个数:{},总用时:{}".format(_TOTAL,_PASSED,_FALLED,_ERROR,_RERUN,_TIMES,))


   

 